package com.shenyaocn.android.dualcamera;

import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.hardware.Camera;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

public class TakeNow extends AppCompatActivity implements Camera.PictureCallback, Camera.ShutterCallback {
    private SurfaceView surf;
    private Camera camera;
    private String schoolID="学校编号";
    private String teacherID="教师编号";
    private String studentID="学员编号";
    private String speed="车速";
    private String carID="车牌号";
    private String time;
    private String GPS="GPS";
    private boolean sure=false;
    private int count=10;
    private TextView timer;
    private AlertDialog dialog;
    private String tag="";
    private Handler handler=new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (count>0){
                if (time!=null) {
                    timer.setText("("+count+"s)");
                }
            }else {
                if(dialog!=null){
                    if (dialog.isShowing()) {
                        dialog.dismiss();
                    }
                }
            }
        }
    };


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_take_now);
        initIntent();
        surf= (SurfaceView) findViewById(R.id.surface);
        surf.getHolder().addCallback(new MyCallBack());
        takePhoto();
    }

    private void initIntent() {

    }

    @Override
    public void onShutter() {

    }

    @Override
    public void onPictureTaken(byte[] data, Camera camera) {


    }


    private void takePhoto() {

    }


    class MyCallBack implements SurfaceHolder.Callback{

        @Override
        public void surfaceCreated(SurfaceHolder holder) {
            Camera.CameraInfo info = new Camera.CameraInfo();
            for (int i = 0; i < Camera.getNumberOfCameras(); i++) {
                Camera.getCameraInfo(i,info);
                if(info.facing==Camera.CameraInfo.CAMERA_FACING_FRONT){
                    camera=Camera.open(i);
                    Camera.Parameters pa = camera.getParameters();
                    pa.setPictureFormat(PixelFormat.JPEG);
                    pa.setPictureSize(800,600);
                    camera.setParameters(pa);
                    camera.setDisplayOrientation(180);
                    try {
                        camera.setPreviewDisplay(surf.getHolder());
                        camera.startPreview();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }

        @Override
        public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {

        }

        @Override
        public void surfaceDestroyed(SurfaceHolder holder) {

        }
    }
    @Override
    protected void onResume() {
        super.onResume();

    }
}
